﻿using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Microsoft.Azure;

namespace CodePlex.Resourceful.Examples
{
    public static class AzureBlobStorageExample
    {
        public static void Go()
        {
            string storage = Environment.GetEnvironmentVariable("AZURE");

            string accountName = storage.Split(':')[0];
            string base64key = storage.Split(':')[1];


            AzureBlobStorageClient client = new AzureBlobStorageClient(accountName, base64key,false);
            client.Timeout = TimeSpan.FromSeconds(20);
            client.Tracer.AddListener(Console.Out);

            var container = "c" + Guid.NewGuid();
           // var container = AzureConstants.RootContainer;

            client.PutContainer(container, null);
           
            try
            {

                client.SetContainerACL(container, true);

                NameValuePairs metadata = new NameValuePairs();
                metadata[HttpHeader.ContentType] = MediaType.TextPlain;
                client.PutBlob(container, "foo", metadata, () => Utils.ToStream("bar"), true, null, null);
                client.HeadBlob(container, "foo", null);

                client.GetBlob(container, "foo", false, null, null);

                client.CopyBlob(accountName, container, "foo", null, container, "foo2", null, null);

            }
            finally
            {
                client.DeleteContainer(container, null);
            }



        }
    }
}
